package com.lm.skywalking.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/log")
public class LogController {
    private final Logger logger = LoggerFactory.getLogger(LogController.class);

    @RequestMapping("/info")
    @ResponseBody
    public Map<String, Object> showLog(){
        logger.info("info日志");
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "info");
        return map;
    }

    @RequestMapping("/test")
    @ResponseBody
    public Map<String, Object> test(){
        long start = System.currentTimeMillis();
        long result = calculateSum(1000000000);
        long end = System.currentTimeMillis();
        System.out.println("Result: " + result);
        System.out.println("Execution time: " + (end - start) + "ms");
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "info");
        return map;
    }

    private  long calculateSum(long n) {
        long sum = 0;
        for (long i = 0; i < n; i++) {
            sum += i;
        }
        return sum;
    }


}
